/*
* Copyright© 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.netty.common.mq.producer;

import com.google.common.collect.Maps;
import com.laihuichuxing.netty.common.mq.dto.*;
import org.apache.rocketmq.spring.starter.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Description:
 *
 * @author YangGuang
 * @since: 1.0
 * Create Date Time: 2018/10/12 9:32
 * Update Date Time:
 */
@Component
public class PositionProducer<T extends PositionDto> {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    /**
     * Description: 定位
     * @param t t
     * @author YangGuang
     * Create Date Time: 2018/10/10 17:09
     * Update Date Time:
     */
    public void position(final T t, String topic) {
        Map<String,Object> msg = Maps.newHashMap();
        if (t instanceof PassengerPositionDto || t instanceof DriverPositionDto) {
            msg.put("latitude", t.getLatitude());
            msg.put("longitude", t.getLongitude());
            msg.put("mobile", t.getMobile());
            msg.put("cityCode", t.getCityCode());
        } else if (t instanceof DriverListenDto) {
            DriverListenDto driverListenDto = (DriverListenDto) t;
            msg.put("token",driverListenDto.getToken());
            msg.put("cityCode",driverListenDto.getCityCode());
        } else if (t instanceof DriverStrokeDto) {
            DriverStrokeDto driverStrokeDto = (DriverStrokeDto) t;
            msg.put("latitude", driverStrokeDto.getLatitude());
            msg.put("longitude", driverStrokeDto.getLongitude());
            msg.put("cityCode", driverStrokeDto.getCityCode());
            msg.put("orderId",driverStrokeDto.getOrderId());
            msg.put("mobile",driverStrokeDto.getMobile());
        }
        rocketMQTemplate.syncSend(topic, msg);
    }
}
